﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.IO;

public partial class Web_POreport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Purchase Order Report";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }
        if (IsPostBack==true )//generate report
        {
           
                Genreport();
                Genreport();
                
            
           
        }
      
    }

    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        try
        {
            Genreport();
        }
        catch
        {
            Response.Redirect("404.aspx");
        }

    }

    public Boolean Genreport() 
    {
        try
        {
            ReportDocument reportdocument = new ReportDocument();
            reportdocument.Load(Server.MapPath("Bin/POreport.rpt"));
            reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
            reportdocument.SetParameterValue("From", ASPxDateEdit3.Text);

            reportdocument.SetParameterValue("To", ASPxDateEdit4.Text);

            //System.Windows.Forms.ToolStrip oToolStrip = (System.Windows.Forms.ToolStrip)CrystalReportViewer2.Controls[0];
            //oToolStrip.Items[18].Visible = false;
            po.ReportSource = reportdocument;

            return true;
        }
        catch
        {
            Response.Redirect("404.aspx");
            return false;
        }
      
    }
}